//
//  LSHomeSectionCell.m
//  LookScore
//
//  Created by wr on 2017/12/8.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSHomeSectionCell.h"



#pragma mark 🔥 LSHomeSectionCell

@interface LSHomeSectionCell()

@property(strong,nonatomic)UIImageView *headImage;

@property(strong,nonatomic)UILabel *titleLab;

@property(strong,nonatomic)UILabel *timeLab;

@property(strong,nonatomic)UILabel *readLab;

@end


@implementation LSHomeSectionCell

+(LSHomeSectionCell *)HomeSectionTableViewCellBytableView:(UITableView *)tableView{
    LSHomeSectionCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSHomeSectionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    UIImageView *headImage=[[UIImageView alloc]init];
    headImage.image=[UIImage imageNamed:@"MineHead"];
//    headImage.layer.cornerRadius=2;



    self.headImage=headImage;
    [self.contentView addSubview:headImage];
    headImage.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).centerYEqualToView(self.contentView).widthIs(76).heightEqualToWidth();

    [self.contentView addSubview:headImage];
    self.headImage=headImage; headImage.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).centerYEqualToView(self.contentView).widthIs(76).heightEqualToWidth();

    
    UILabel *titleLab=[[UILabel alloc]init];
    titleLab.font=LSFontSize15;
    titleLab.textColor=LSTitleGrayColor1;
    titleLab.textAlignment=NSTextAlignmentLeft;
    titleLab.numberOfLines=2;
    [self.contentView addSubview:titleLab];
    self.titleLab=titleLab;
    titleLab.sd_layout.leftSpaceToView(headImage, 20).topEqualToView(headImage).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1);
    
    UILabel *timerLab=[[UILabel alloc]init];
    timerLab.font=LSFontSize10;
    timerLab.textColor=LSTitleGrayColor2;
    timerLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:timerLab];
    self.timeLab=timerLab;
    timerLab.sd_layout.leftSpaceToView(headImage, 20).bottomEqualToView(headImage).heightIs(20);
    
    UILabel *readLab=[[UILabel alloc]init];
    readLab.font=LSFontSize10;
    readLab.textColor=LSTitleGrayColor2;
    readLab.textAlignment=NSTextAlignmentRight;
    [self.contentView addSubview:readLab];
    self.readLab=readLab;
    readLab.sd_layout.leftSpaceToView(timerLab, 5).bottomEqualToView(headImage).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(20);
    
    UIView *lineView=[[UIView alloc]init];
    lineView.backgroundColor=LSLineGrayColor;
    [self.contentView addSubview:lineView];
    lineView.sd_layout.leftEqualToView(self.contentView).bottomEqualToView(self.contentView).rightEqualToView(self.contentView).heightIs(1.f);
    
   
}
-(void)setListModel:(LSHomeArticleQueryList *)listModel{
    _listModel=listModel;

    [self.headImage sd_setImageWithURL:[NSURL URLWithString:listModel.ListImgUrl] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
    }];
    
    //圆角
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.headImage.bounds byRoundingCorners:UIRectCornerAllCorners  cornerRadii:CGSizeMake(3, 3)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.headImage.bounds;
    maskLayer.path = maskPath.CGPath;
    self.headImage.layer.mask = maskLayer;
    
    self.titleLab.text=listModel.ArticleTitle;
    
    NSString * timeStr = [listModel.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    
    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString * dateString1 = timeStr;
    NSString * dateString2 = [CommonClass getCurrentTimes];
    NSDate * date1 = [df dateFromString:dateString1];
    NSDate * date2 = [df dateFromString:dateString2];
    NSTimeInterval time = [date2 timeIntervalSinceDate:date1]; //date1是前一个时间(早)，date2是后一个时间(晚)
    // 结果就是两个时间点之间相差的秒数，如果要精确时间，修改NSDateFormatter的形式，并把两个时间对应调整就行
    if (time < 300) {
        self.timeLab.text = @"刚刚";
    }else{
        self.timeLab.text = [CommonClass timestampToString:listModel.TimeStamp];
    }
    self.readLab.text=[NSString stringWithFormat:@"阅读 %ld",(long)listModel.IpReadCount];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end



#pragma mark 🔥 LSHomeSectionChooseCell

@interface LSHomeSectionChooseCell()

@end

@implementation LSHomeSectionChooseCell

+(LSHomeSectionChooseCell *)HomeSectionChooseTableViewCellBytableView:(UITableView *)tableView{
    LSHomeSectionChooseCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSHomeSectionChooseCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
       
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
       self.backgroundColor=LSBackGroundColor;
//        [self addContentView];
    }
    
    return self;
}
- (void)setArrayT:(NSArray *)arrayT{
    _arrayT = arrayT;
    [self addContentView];
}
-(void)addContentView{
//    NSArray *array=@[@"HomeSMG",@"HomeBJSingle",@"HomePlayTricks",@"HomeGrounderR"];
    NSArray *array=@[@"HomeBJSingle",@"HomePlayTricks",@"HomeGrounderR"];
//     NSArray *arrayT=@[@"资料库",@"专家排行",@"玩法技巧",@"热门话题"];
//    NSArray *arrayT=@[@"专家排行",@"玩法技巧",@"热门话题"];
    
    UIView *backView=[[UIView alloc]init];
    backView.backgroundColor=LSTitleWhiteColor;
    [self.contentView addSubview:backView];
    backView.sd_layout.leftEqualToView(self.contentView).topEqualToView(self.contentView).rightEqualToView(self.contentView).bottomEqualToView(self.contentView);
    
    CGFloat width=(LSScreenWidth-(self.arrayT.count-1)*10)/self.arrayT.count;
    for (int i=0; i<self.arrayT.count; i++) {
        UIButton *button=[UIButton new];
        [button setTitle:self.arrayT[i] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:array[i]] forState:UIControlStateNormal];
        [button setTitleColor:[CommonClass colorWithHexString:@"#4d5665"] forState:UIControlStateNormal];
        button.titleLabel.font=LSFontSize15;
        CGFloat widthF=[CommonClass textWidthByString:self.arrayT[i] sizeFont:15 layoutWidth:width spaceWidth:0];
//        UIImage *image=[UIImage imageNamed:array[i]];
        button.titleEdgeInsets=UIEdgeInsetsMake(50,-50, 0, 0);
        button.imageEdgeInsets=UIEdgeInsetsMake(-20, 0,0, -widthF);
        [button addTarget:self action:@selector(jumpDetailOrchooseMoreEvent:) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:button];
        button.sd_layout.leftEqualToView(backView).offset(15+width*i).topEqualToView(backView).widthIs(width).bottomEqualToView(backView);
    }
    
    UIButton *chooseMoreBu=[UIButton new];
    [chooseMoreBu setImage:[UIImage imageNamed:@"OtherAdd"] forState:UIControlStateNormal];
    chooseMoreBu.titleLabel.text=@"";
    [chooseMoreBu addTarget:self action:@selector(jumpDetailOrchooseMoreEvent:) forControlEvents:UIControlEventTouchUpInside];
//    [backView addSubview:chooseMoreBu];
    
    chooseMoreBu.sd_layout.topEqualToView(backView).widthIs(30).heightIs(40).rightEqualToView(backView);
    
    
    
    
    
}

-(void)jumpDetailOrchooseMoreEvent:(UIButton *)sender{
    
    if (self.buttonTargetEventBlock) {
        self.buttonTargetEventBlock(sender.titleLabel.text);
    }
}


@end
